Added query middleware