refactoring (extract temp to query)