It would be great if you could define these function at the module-level and not in an inner scope: things are easier to test and debug in outer scopes.