refactor query string building into a method