Reworked handle_msg.