Undo and redo bug fix

Fixed add and remove element commands. The removed elements are added to their original positions after applying undo.