Avoid null in foreach loops