Added some test cases and fixed a bug found in unit test. There are still some test case failures.