Add unit tests and more robust replacement logic