Finishing tree creating algorithm