move sync code into method