clean up generation code.
Issue #131, index missing categories