added more test cases and refactored