Script modified to consider instance id as key for dict