Fix duplicate undo entries (fixes #1105)