Added some safty checks for entity deletion
Merge pull request #287 from dswd/fix-on-delete

Added some safty checks for entity deletion