fixing an overflow bug