changed pow() to use exponentiation by squaring, and changed toArray() and depth() so that they no longer visit nodes with null values