Merged changes from dev branch.
Merge branch 'dev'
Fixed issue with not properly closing C++ models in some circumstances.