JS: refactoring