Refactor js

**Resolves issues #777, #780, and #789.**

---

Rewriting our js to be more readable and less hacky.