some important fixes and improvements on tree