Use uint16_t instead of unsigned short for portability