Compare this, line by line, character by character, with the original. Study each changed character using the documentation to try to understand why the change was made.
If I have made a change then compare the value calculated by the original method and the value calculated by the new method. Use FullForm[value] on each so that Mathematica will hide less about what the result actually is in each case. Use that to try to understand why the method used was changed.
And carefully check some of the results by hand to make sure the results are correct and that there are not more errors in this.
In Mathematica almost anything can be done at least twelve different ways. Some will be faster, some will be easier to understand.
Some parts of the notebook could be made simpler, but I have tried to make the smallest number of changes to get what I think you want.
It was very helpful that you provided both the notebook and the data file it was to use. That made it possible to test the changes to see they work.
Attachments: