Refactored main().