Refactored auth stuff