Each block in this section seems like it could be moved to a function with a descriptive name that performs each action.