Refactor auth