fix a bug that didn't consider overflow correctly