refactor verify_message and friends