fix bugs in cpm.c