moved filtering into its own function