refactored some codes.