Change mask_data implementation

Use iterators instead of indexing and range