Bug fix and enhancement for code-gen.c requested by waterwingz.