Updated sync code for realms.