refactored filter code