Refactored some codes.