Clean up, add comments
Add edge cases for undo-push