added thread and while loop