Fix preallocated tree build and search