Adding Test Cases and refactoring