refactor login and logout