huge code rearrangement to make the codebase easier to maintain