fix sample_traj_and_print (no more infinite loop and segfaults)