More thread-safety in libcfnet and some API cleanups.

Passes all tests even though it became more complex than expected, please review appropriately.