Index val on 'id' not on 0
Use a different variable so we don't step over the one used in the outer loop
use dotted notation