Refactored code/example to use bit masks