This function and the one below it seems unnecessary as they are only called once and are defined immediately below this block and simply makes the code less readable.

If you have a block of code that needs to run multiple times and takes the same arguments, then make it a function; but otherwise put the code inline as it's more logical.