lifted state machine code and toying around