Refactored everything in the same basic filter function