Fixes to work with the new TLS api.

TLS keys are no longer functions but static variables.
TLS-related functions are no longer unsafe =)