refactoring the plot function