Breaking the JS into modular sections

Fixes #339.
Fixes #312.