Bug fix for deleting entities