Fixed major bug in replacement process.