Fixed code to check array length