refactoring javascripts