refactor and rearrange