Gracefull termination code added