changed algorithm to produce collections