made improvements to handle uninitialized loop variables