Refactored much of the auth code into tentlib module