Prevent crash for some weird queries
Use defined and !defined instead of ne undef and eq undef respectively