some tweaking of Bernoulli