Refactor - moved as much stuff as possible out of the main .html files into separate template and script files