bug fix and more test cases