debug code & tidyup of idgen.c
debug code & tidyup of idgen.c