Refactor sendMessage