first version with tree structure