First running version of sync, not thoroughly tested yet