refactor the code2