updated code with adding option for selecting masking