Fix NoneType error in remove_messages().