refactored code with piechart