Bug fix; fix test cases