Re-organized auth code. WIP