Refactord and reorganized code to put functions near each other that either go together or are related. Also divided the code into sections with comment blocks to make it easier to understand what functions do and how some are related to each other