Refactoring sync method.

Now we return the error code by reference.