Fix #495. Enforce write permissions correctly