Refactoring and adding tests for the correct implementation of filters