Breaking the JS into modular sections

Big dramatic changes. :confused:

Fixes #339.
Fixes #312.