Added query error tracking