more test and some refactoring