sync algorithm