Massive changes to JS. OOP style rewrite.