moved distribution code to struct