added test cases; refactoring