call cleanup-function in thread_local_ptr
some fixes