fixing issue when handling graceful termination