Added better error logging to authentication