use closures instead of functions