Added a bunch of foreign keys.
Fixed one issue with the R script.