handle_end_msg corrected