added thread control