Refactor repetitive mask value code