JS Refactoring