Refactor javascripts a little