Use the undo stack to set the modified bit
This way it's much easier to track whether we are modified or not