fixed var unnecessarily defined inside the loop