Refactor javascripts

Fixes #45