Implementing the method replaceItem