added state machine stuffs