added a syncLoop function