(minor) should this really be a size_t? Perhaps something (potentially) smaller like unsigned int? Even uint8_t would have more than enough range.