Fixed bug where resulting trajectories would not be written out in
correct order