added code for normal close in main