fix a bug in advance replacement