I think what is happening is that interior detection is taking precedence over boundary detection. Instead, just flag the point as interior, then outside the loop, check the boundary first, then if interior return interior color, else return exterior color.
While your derivative is correct, it can be simplified to -2z/(z2-1)2 by multiplying out the numerator instead.