Reduced spawned processes and subshells of the script by about half

As you can see here, the rearranging of certain if groups and reducing the number of times cat was piped into grep, the spawned processes and subshells from the script have been reduced by about 50%:

# wc -l before_changes.txt after_changes.txt 
 132 before_changes.txt
  65 after_changes.txt
 197 total