Js refactor

This takes care of moving the JS around. Stylesheets next.