changed filter function so that it can be used as a piping script