Refactored segment loading and integrated changes. Further integration still needs to be done.
Removed, fixed, and added tests.
Merged conflicts between some of the merged branches.