Refactoring into sessions