refactoring JS