cleaning up output and using random numbers to build the tree