Added foreign key handling