fix bug and refactoring
fix bug and refactoring