Fixed a bug, added more test cases