fixed serializing painfullness and conversion to c using malloc