move functions to top of file as improve readability. no logic modification.