Corrected replacement loop.