Refactoring root-finding