add comments; clean up main()