cosmetics and test units
allocate memory in chunks to reduce the number of calls to realloc() while building the encoded buffer

minor cosmetics as well