fix bugs, update test code