Refactor javascripts