The script as stands would seem to attempt to unset %query_ $+ %errnick... i.e. the concatenation of the value of the variable %query_ and that of %errnick (assuming it attempts to evaluate the $+ at all), however, even using $+(%,query_,%errnick) (which I would assume would evaluate before the unset was performed) didn't work until I wrapped it in an eval:
//unset $($+(%,query_,%errnick))
What I also note is that using unset -s with any of the invalid cases does not show anything; perhaps an error message would be useful.