I agree that the replace service is unlikely to be the problem here.
Actually this type of problem, changes being discarded when mapping within a loop or loops, is a familiar problem when working with loop statements. Here is an example of such an issue.
Tim