fix lurking variable scope bug