Reorder some definitions to reduce undeclared var warnings
Reorder refs to reduce number of undeclared var warnings
Revert 1bbd7e516df0c3fd6ebdd15aa65bc4a38707ecdd for some files