restructured character as a state machine