[Refactor] Extract method.
[Refactor] Extract method.
[Refactor] Extract method.
[Refactor] Extract method.
[Refactor] Change outside variables to static variables inside the function.
[Refactor] Extract method.