add condition to check array is not nil