Fix overflow bug when reading