Optimization & cleanup of replace sequence.