Implementing replace method (closing issue #225)