refactor code to use requirejs