refactor the  code