improved thread control