Fixed variable capturing bug