finishes state machine implementation