fix numerical derivative calculations