refactoring keep_alive function in SessionManager