Fixed bug in check_derivatives