more refactoring in utils.js