Add JSON support for response. Update server_address from response. Reorganize code.