fix query hash chaining logic