New branch for code review.
Fixing bugs in control structure. Added stability and functionality to
Learn state.