Refactor js

**Resolves issue #780.**

---

Rewriting our js to be more readable and less hacky.



button_to_form can be removed. Not used anywhere.