Updated with Dice algorithm.