Moved taxonomy filtering into its own function