added more test cases and fixed bugs