Bugfixes to gradient and trajectory storing.