Tweakes and fixes for foreign key feature