re-implemented using stdint.h