added some helpful debug output
cope with primary keys with multiple segments
cope with multiple segments in primary key