Story/foreign keys

Please go over the commits.