Declare variables at top of function

Change-Id: Ie258f0f2bc9ebdefb1387acd21729fafcd205d61