generate_client_id and some error checking.
More error handling.