Extracted several logically independent parts from resolveChild()