Refactored out trajectory code