Added more TLS features and fixed some object lifetimes