There is an overuse of the `mod` variable name here. Having `mod` passed into the loop and then altered within the loop makes the current state of `mod` harder to track down in the future.

In an attempt to remove the mutation of variable state, I prefer creating a new variable when an existing variable needs to be changed or altered. Giving it a more descriptive name of why it changed in that new variable.