Reconstructed the logic in the branching construct in main().