Consolidate main() function