Merged with Habib's latest sync fixes