Refactor to make auth more modular