Use log instead of fmt for debugging output
Shift closures into first-class functions.