New Feature: Undo command
Some minor code cleanup and optimization