Refactored the API out of the authentication code.