Added more test cases and fixed some bugs