modify some bugs and add test codes