Fix integer underflow bug

this version handles x = 1 without underflow