Major refactoring of JavaScript to be object driven and namespaced

This closes #4