Added code to detach session