More intelligent masking code