Fix overflow bugs