Example of javascript refactoring