[fix] some bugs, added tests