Update masking method and add more comments