more replace() tests, refactoring