Break this query out and check for null before referencing the first item in the array otherwise you will get a type error.