big changes to session handling. Fixed at least one bug, hopefully did not break anything in the process.