updated replace method