A State Machine implementation