fix bug
refactor the code