wrap sync in seperate thread
small improvements global variable sync