Added foreign key references and applies table