refactoring and some improvement