Added missing undo and minor refractor