make sure subarray is defined before accessing element