refactored to work with require.js