Fix overflow bug.

Thanks to Andrea.