corrected impl of replaceall