use Extract method to refactor some code