Fix join_cluster script to avoid infinite looping and add logging.