refactored code in global.js