Refactored the code to display the graphs