Improved templating and JS, moved php to separate files