Working replace function (but no save function yet)