Distribution code almost working