fixed a minor bug in replace