bug fix and test code update