Added more comments describing logic in main().