Make chunkify a free function