refactor of query to only not convert to criteria if criteria doesn't exist.