Added a lot of rollback code to ensure clean session closing.