Something is funny in the derivative function. When I zoom in to the graph, there are circles. This basically means that some x values are counted twice. Need to fix.