added test cases
refactored code