Broke main down into multiple functions, cleaned up the code a whole lot