Added sync code, seems to work for the "all" case. Not rigorously tested yet