Changed location of 2 function definitions to before where they are first used.