cleaned up the plot function a bit