added threads, clean up not correct yet but it works