Added additional check in cot_clear_messages; fixes #1353