Fix a few bugs in the protection code.