Finished buildBitmask function. Testing is required