Refactor application javascript