Bug fix in trajectory function.