Refactoring to use require.js