Minor: Move nested functions to top level.

Change-Id: Ia6acad5b9bd635f8b5de9014b3c24ae06d90a834