Refactor filtering to a chainable, more flexible design