update filterValues function to be recursive