tidy up masking code