Updated the function that checks array validity