small bug in the replacement code