rearrange and comment code.