Compactize query code.