added sync at beginning and end