Added a routine to properly close the models before quit application
avoiding crashes