state machine correction

a few variable declaration to be done. Still in progress.