Fixed accumulation and boundary detection code to make good intervals.