improve the probability code