Fix incorrect behavior for small number of intervals.