refactor to allow script to handle singleton collections