Refactoring to have a state class. Added some comments, added some command features.