Fix #953 Close session properly

Fix tests