Fix ScopeDelete

Close #2781
Merge pull request #729 from sigurdteigen/master

Fix segfault resulting from bad ScopeDelete