Fix indexing bug when generating packages.