Clean up and bug fix

-Use functions to clean up main execution
-Fix bug where winning in middle column was not detected