= changed type of substitution, simplified algo