recursion would help but I can't figure out how to pass a nil value in the first query hash