Fix #953 Close session properly

Fix tests
Merge pull request #365 from nlegoff/fix_953

Fix #953 Close session properly