Fixed overflows and endian issues