Renamed variables to better represent the types of variables they represent. Reordered some of the functions so that the functions don't need to be declared before they are used.