added robustness to array checking