Replace excessive for loops with a regex
Clean up crufty for loops