Final bugfixes to trajectory code.