Refactoring: Replace Temp with Query