Added some fixes to the authenticate() method.