Fixing the plotting function