Rearrange code in dithering module