optimizing sync code, two versions