Implement replace method