Refactored Newton Raphson in preparation for phase envelope calculations

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>
Phase envelope works for first half, but breaking in the critical region

Signed-off-by: Ian Bell <ian.h.bell@gmail.com>