Added unittest for local variable declaration. Fixed bugs it uncovered.