Refactor auth stuff