Better handling of undefined query