added comments for state machine