added threads and res functions