rewrite code to use require.js