MVC.DOM: fixed memory leak (for deleted models in app.closeDocument() & a few refactors)