Optimization using closures