Updated Sort/Merge code based on updated Design Doc

Implemented the pseudocode from the Design Doc. Not a working copy yet.
Testing in progress.