Refactoring, optimized sync()