Added better sync code