Changed to use tree structure.