reorganize helper functions

Reorganize / re-order the helper functions to be defined before they are
called.
a better way to enter nirvana mode
coding style clean-up