refactor handle_message