Mostly aesthetic changes. Rearranged a number of the functions.