Changed apply_filter function, not tested