moved foreign key loading logic to own function