rewrote the reingold-tilford algorithm