wip: need to design the state machine and cleanup the state code in main.c