code reformat and rearrange