changed plot_trajectory function slightly