Design and Implementation of a State Machine Framework