Fix bug when removing objects.