add array_filter to prevent empty arrays