Refactor some codes.