moved code to mem.c and allcodecs.c