Fix closing of sessions