Use mask_write

Closes #148