Fix overflow (not tested for correctness).