Tweaked filter function