Fixed errors when removing entities.