fix some bugs and add test scripts