Add tests for replace(), fix bug.