rewriting unit size generation code