Slight generalization to other distributions.