The previous version was unusable because of the check for duplicates. This is a temporary working solution. To be continued...