Fix bug 1589: Improve deletion of models