refactor null-or-empty query