Refactor out functions using newton's method