Format output into a chart.
Cleaned up code and added appropriate documentation.