Fix some bugs in remote/sync (still not complete)