correctly handle when session becomes invalid