implement replace method.