moved sync statement higher up