modified root function

TODO: make roots calculate faster by limiting recursion