Eliminated the loops and arrays and used an extra replace instead.