Refactor to reduce closures.