Refactor using requirejs