Use filter fn instead of if statement