improve the replacement method