Fixes #2654 - Rewrite master as production when only one environment is found
Fixes #2659 - Use gsub in a non-destructive manner