refactoring of cloud syncing code