Add connect_to_realm function