Reduce variable scope.
Use %d for integer instead of %i for consistency.