Fix a few bugs with how masking was handled
Add more tests to reach 100% coverage