state machine implemented
structural clean up