Use more functional style in building filter chain

Thanks @dchelimsky