Added support for categorical indices.
fixed bugs for categorical indices.