refactor and implement requirejs