improved distribution code