YF Piercing Arrow type skill and row targeting issue.

Im trying to make a skill like piercing arrow, but it doesnt seem to target properly. When selecting the target , it seems to randomly target another enemy in the same row as initial target, the back row hits works.

I have a different setup for my skills so I have it do a whole action to deal damage at the same time (important because of the next step).
Then it casts a state on user depending if it had that state previously, if it did not have that state it would apply the state. If I set this up differently, 2 hits would trigger the state 60 then remove it for state 50 in one attack. The goal is if you cast this skill the next time you use it will add the buff (state 50)

In any case even when I remove the whole and target actions and leave it as default it still doesnt target the right enemy all the time.
Code:
<Whole Action>
action animation                    // hit all targets and deal damage at the same time.
wait for animation
action effect
if user.isStateAffected(60)            // if user has state then
remove state 60: user                // remove state
add state 50: user                    // add new buffed state
else
add state 60: user                    // adds state if currently doesnt have state
end
</Whole Action>

<target action>
</target action>

<Custom Target Eval>
// Get the target's current row.
var row = target.row();
// Get the target's allies.
var group = target.friendsUnit();
// Loop through each of the rows in your game.
for (var i = row; i <= Yanfly.Param.RowMaximum; ++i) {
  // Get the members of the row's alive members.
  var members = group.rowAliveMembers(i);
  // Check if the member group is larger than 0.
  if (members.length > 0) {
    // Add a random target from that group.
    targets.push(members[Math.floor(Math.random() * members.length)]);
  }
}
</Custom Target Eval>

Original thread: https://forums.rpgmakerweb.com/threads/yf-piercing-arrow-type-skill-and-row-targeting-issue.121767/