Refactor js

Rewriting our js to be more readable and less hacky.


86,87 are redundant