Extracted some methods with refactoring.