Refactor js

Rewriting our js to be more readable and less hacky.


Having one or the other accomplishes the same thing.