Solving problem with list of steps in substitution