working plot function