fixed foreign key handling