Fix for MSVC warnings

converting uint32_t to uint16_t
signed/unsigned comparison