refactored the filter code