refactor the codes.