add test cases, doing some refactoring