Added undo, refactored