Fix tree indexing