Fixed a bug in the remove code