Replace table by a tree