Refactor js

Rewriting our js to be more readable and less hacky.


Use promises rather than success call back.