Main application refactoring

Moved test harness code to own file
Moved state machine to own file