move function definitions outside of a function

Hidden functions are difficult to test and should be avoided.
Merge remote-tracking branch 'kanzure/cleanup-hidden-functions'