Added query logic