Fixed bug in derivative.  Fixes #3787