Major js restructuring. Broke out js into separate files for clarity, but not tested on device yet.