Improve robustness of the sync module. Fixes #118. merged-on-behalf-of: Leonid Kramer <l-kramer@users.noreply.github.com>