added threads. working well. commenting now and reorganizing