Added filter function, refactored...