Refactored and added more test cases