Now we have a separatted function to build the query