                     tail_flags[ITEM] = 1;
                     thread_segment_idx++;
 
-                    valid_segment = (thread_segment_idx < next_thread_segment_idx);
-                    segment_end_offset = (valid_segment) ?
-                        d_segment_end_offsets[thread_segment_idx] :
-                        num_values;                                                         // Out of range
+                    if ((valid_segment = (thread_segment_idx < next_thread_segment_idx)))
+                        segment_end_offset = d_segment_end_offsets[thread_segment_idx];
                 }
                 else if (valid_value && !prefer_segment)
                 {

    // Parameterized BlockScan type for reduce-value-by-segment scan
    typedef BlockScan<PartialReduction, BLOCK_THREADS, SCAN_ALGORITHM> BlockScan;

    // A cache item that can either be a value or a segment-ID
    union CacheItem
    {
        SizeT segment_idx;
        Value value;            // TODO: fix for non-default-constructible value types
    };

    // Shared memory type for this threadblock
    struct TempStorage
    {

        };

        // The first partial reduction scattered by this thread block
        PartialReduction first_partial;
    };

    //---------------------------------------------------------------------
