Bug fix in trajcetory function.