working collate program