Refactor login/logout.