simplify filter function using the ``for`` construct