modified foreign key logic