last working version, with sync threads