Refactored main and pulled the state out into another file as a function, refactored those functions