add check for null elements in arrays