Adjust the algorithm to take overflow into account