Some refactoring and addition of test case