Fun with JS refactoring