Fix itoc and memory allocation