Fixes for the replace function.