refactoring
add a beginning of state machine