Close sessions properly