Thread sync + cleanup