Implemented StateController, refactored panel code.