Thank you for your prompt response!
I made those corresponding changes but now when I save the mask at the end, it gets saved as a white PNG:

image1000×1000 217 Bytes

Instead of this:

image1000×1000 9.8 KB