finish the replace_ methods (and fix them) and add tests