Refactor sendMessage into utils module.