Handle NaNs by staying away from them rather than flattening templates.
Better NaN check.
New binning and tree location.
Correct loops.