Extract this code block into its own method.

Change-Id: I43cc4ae350455c104d079e6aaaa28eabbd6c04e7