Use lock to avoid race condition in tf calls; also, no double functionality