cleanup and add comments to collect and uniquify