Added more test cases + refactoring.