Fixes bug 260. Improvements to the undo system all around.