Add index WriteTreeTo + test