Fixed a couple of bugs related to the replacing mechanism