made some changes to the plotting function