working code to collect instances