Get correct document lengths
Almost fixed, only need to get correct wtd in innermost query