Refactoring and improved filtering