Refactored the diffing algorithm. Added comments.