Step 4 - replace temp with query