Add a function to update a session continuously and refactor codes