Refactor authentication code
Merge pull request #656 from SamWhited/authrefactor

Refactor authentication code