Update SortYieldFiles

- Declare variables as global.
- Faster code by reducing loops.