Refactor js

Rewriting our js to be more readable and less hacky.


Should set attr to disable loading spinner here.