Fixed authentication bug and added code to check QueryFailure flag.
Make the callers of Receive be the ones responsible for checking the QueryFailure flag.