Slight optimization of solveReferences.