refactor javascript into modular files within directories corresponding to their views; various tweaks to the JS code itself