put this bunch of private methods in the end of the class. specially the replace... and the rewire... methods