refactor and rearrange code packages