Split JS into modules

Split JS into different modules which interoperate via callbacks.
Neatened up JS and HTML code to lighten the network load when fetching
the app for the first time.