cleanup entity scripts when changing domains or entity is deleted

ok - will fix. I also just pushed a new feature to this PR... so you'll want to review those changes too.. sorry.