Move filtering code to Filter class