created state machine implementation