Implementation of tree creation