Basic JS refactoring