added thread to code