updated plot function