rewrite the code of session manager