Test coverage and other fixes

This is an ancient branch that doesn't seem to have been PRQed. Time to fix that.