fix minor issues and some refactoring and more test