In general, try to get away from C style 'declare vars at start' style. Move declarations as close to first point of use as possible. So I'd move this to the line right above where you call runCommand.