Refactoring: Use html templates instead of code/html mixture
Use something like a templating engine to load separate html files from disk and fill them with variables - instead of the current mixture of code inside templates
Use something like a templating engine to load separate html files from disk and fill them with variables - instead of the current mixture of code inside templates