fixed bug with unsigned integer overflow