Refactor for RequireJS and updated code structure.