fixed tree inversio bug