Fixed bug with replacing and undo/redo