improving dice algorithm