Move error var inside filter function