check for !defined $query rather than !$query