state machine in main complete as well as cleaned up code in other files.