check for !defined $query instead of !$query