added reorder logic to bvh code