refactor and rearrange every thing