query.c: Tidied CORRELATE QUERY code a bit

Renamed variables and moved declarations to the top.  Report errors on empty
input sets.

Signed-off-by: Morten Hustveit <morten.hustveit@gmail.com>