state machine added for tutor - makes it easier to understand.
minor improvements