refarctored code and applied requirejs