Refactored to modular code using require.js