This commit finally unifies all main() functions and moves the few remaining application-wide functions where they belong.