tree scaling algorithm seems to work