Query and tests Fix

Query Refactoring