state machine written with python