added code for terminating application