Add some test cases.
Fixed some bugs