Refactored and added a couple of test cases