Refactored main()