Modularized procedure from main()