improve logic for sessions