refactor filter write to DOM into a function