Closed-over variables get wrong values