[INTERNAL] main() restructured