Minor optimization (maybe not worth doing): you could combine this loop with the previous one--you can just calculate the lowerBound and upperBound (of the original values) at the same time, then add lowerBound to upperBound after exiting the loop.