reduced scope of some loop vars