Refactored filtering code into its own class.