Creating tree structure for nested list