fix addLocal bug; add some tests;