Rewrite using closure to bind names dynamically