refactor out ifquery usage