Bug fixing in arrays