refactor the  code
fix bug