Filter code refactored