rewrite the synchronize function