authentication refactor