Fixed error checking for arrays