Refactor lambda into function.