adding error handling to stats