Refactored to use require.js