check array before accessing it