Refactor and separate the session from the client