Refactor js

 @stewartmccoy please merge the refactor-js branch in to the devel branch. All issues from the refactor should be fixed now.