Tidy up dynamic groups and fix implementation of distributeEntities