improved handling of foreing keys