rearrange code, fix a randomcolor bug