Cleaned up the session closing stuff a bit