JS refactoring