Extract query to its own method