added state machine, not working yet