Fixed and setup the CollectionFactory and made it part of the loop