Added error checking for stats retrieval.