Refactor login-logout