Adding some test cases & refactoring