refactor copy query into method