Fix mask writing.