Authentication refactor