Big refactor.

Split templates and js in to multiple files.