Smart session quitting