Added StateMachine for multithreaded tests.
Refactor, moved samples to Example classes.