Fix tree rebuilding