Refactored to allow for undo/redo.