Move anonymous functions to testable named functions