added apply_mask