Refactor TLS functions.