refactor inner loop to two simple strtok_s calls