moved replacements into function to make it testable