added size_t *datalen = NULL as fourth argument