refactored solution about filter by using only the filter function