Now, read_mask and write_mask works (tested)