optimize iterate through codes