Fix replace issues

Note that I have not actually run any of this code yet....