Added error checking for array size limit.