Turned pie chart generation into separate function.