Condense toNode and toValue code.