Avoid code duplication and restore session semantics