rearrange some codes