Use mask_write

Closes #148
Merge pull request #291 from cmr/mask_write

Use mask_write