moved plot function