Potential fix for #1057

Tests for the undo flag would definitely be a good idea, too.  This quick PR was inspired by #1057