Improve session cleanup logic