JavaScript code reworked to support RequireJS