There were some floating point errors, so now z is part of the root finding, still need some debug