Assert setfield invariant
Fix stupid bug with closed functions in references
Add test for bug