Remove use of lambda with a refutable pattern