Refactured filter functionality