Refactors common subsequence to remove complexity.