fix some logic errors in -undo