Now correctly handles outputs with index >1