Refactoring helper functions to utils.js