Restructured the code deailing with the auth.

This addresses issues reported in #69.