Certbot --expand creates duplicate server settings

I have domains running properly with Certbot but whenever I run sudo certbot -d existingdomain.com,www.existingdomain.com,existingdomain2.com,www.existingdomain2.com,newdomain.com,newdomain.com --expand

It adds additional server blocks below the existing server information and crashes all the domains until I manually edit the file by deleting the extra server blocks and add the newdomain information.

I am wondering if this is because the spacing has been changed from manually updating the file? But it would be great to not have to fix the file each time I run the --expand command.

I am using certbot and nginx

Here is the before running certbot expand:

server {

location = /favicon.ico { access_log off; log_not_found off; }

listen 443 ssl; # managed by Certbot
server_name ~^(www\.)?(.+)$;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mymydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


root /home/.../.../project;

location /static/ {
    root /home/.../.../project;
}

location /media/ {
    alias /home/.../.../.../media/$2/;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
}

}

server {
if ($host = www.existingdomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = existingdomain.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = www.existingdomain2.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = existingdomain2.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot 








listen 80;
server_name 12.345.678.90 existingdomain.com *.existingdomain.com existingdomain2.com www.existingdomain2.com;
return 404; # managed by Certbot

After running

sudo certbot -d existingdomain.com,www.existingdomain.com,newdomain.com --expand

It produced this output:

server {

location = /favicon.ico { access_log off; log_not_found off; }

listen 443 ssl; # managed by Certbot
server_name ~^(www\.)?(.+)$;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


root /home/.../.../project;

location /static/ {
    root /home/.../.../project;
}

location /media/ {
    alias /home/.../.../project/media/$2/;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
}

}

server {
if ($host = www.existingdomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = existingdomain.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = www.existingdomain2.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = existingdomain2.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot 
server_name 12.345.678.90 existingdomain.com *.existingdomain.com existingdomain2.com www.existingdomain2.com;
return 404; # managed by Certbot
















listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
if ($host = www.existingdomain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = existingdomain.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = www.existingdomain2.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


if ($host = existingdomain2.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot 










listen 80;
server_name 12.345.678.90 existingdomain.com *.existingdomain.com existingdomain2.com www.existingdomain2.com;
return 404; # managed by Certbot

My web server is (include version):

The operating system my web server runs on is (include version):
Ubuntu 18.10

I can login to a root shell on my machine (yes or no, or I don’t know): yes

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot): certbot 0.31.0