Undo inconsistencies

The issue is that sometimes instead of the last action being undone the next to last action is undone. While this isn't a show-stopper it can definitely slow down programming. I'm not able to reproduce it. I'm currently running 3.15.1 but I've observed these inconsistencies in previous versions.