fixes pass by reference usage and total array index