Fix extract_values.py so that it deals with trajectories of different lenghts