First refactor of the login infrastructure