Fixes bug in derivative caching, #975