State machine improved