reworked piece generate algo