fixed mistake in loop