Refactored code to include requireJS