Added success and failure callbacks to the authenticate function

Also a refactor, still some minor problems