Dealing with an issue stopping proper program close

added amendment suggested by Andrew Scheller to  aid clean closure