khushal: changed at_exit block