just an update. I am working on what I think is a solution for algorithm 2.  I have added a substruct to handle the issue I think I found when working with suffixes.