refactoring the codes.