Better insert and extracting of boundaries in tree