Extract functions from handlers.js to utils.js