Tcv bitmask fix

Bugfix in library functions, and unit tests.

Please Pull.